<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "address".
 *
 * @property integer $id
 * @property string $name
 * @property integer $tel
 * @property string $phone
 * @property string $province
 * @property string $city
 * @property string $community
 * @property string $address
 * @property integer $uid
 * @property integer $created_at
 * @property integer $status
 * @property integer $code
 */
class Address extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'address';
    }
    public function beforeSave($insert){
        if($return=parent::beforeSave($insert)){
            if($this->isNewRecord){
                $this->uid=Yii::$app->user->id;
                $this->created_at=time();
            }
        }
        return $return;
    }
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name', 'tel', 'province', 'city', 'community', 'address', 'code'], 'required'],
            [['tel', 'status', 'code'], 'integer'],
            [['name'], 'string', 'max' => 10],
            [['phone'], 'string', 'max' => 20],
            ['status','default','value'=>0],
            [['province', 'city'], 'string', 'max' => 8],
            [['community'], 'string', 'max' => 15],
            [['address'], 'string', 'max' => 30],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
            'tel' => 'Tel',
            'phone' => 'Phone',
            'province' => 'Province',
            'city' => 'City',
            'community' => 'Community',
            'address' => 'Address',
            'uid' => 'Uid',
            'created_at' => 'Created At',
            'status' => 'Status',
            'code' => 'Code',
        ];
    }
}
